package com.lxhotel.agentmcp.service;

import com.lxhotel.agentmcp.entity.User;
import com.lxhotel.agentmcp.domain.request.LoginRequest;
import com.lxhotel.agentmcp.domain.R;
import com.lxhotel.agentmcp.mapper.UserMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.util.ObjectUtils;


@Service
public class UserService {

    @Autowired
    private UserMapper userMapper;


    public R doLogin(LoginRequest request) {
        User user = userMapper.selectByUsername(request.getUsername());
        if (ObjectUtils.isEmpty(user)) {
            return R.failed("该账户不存在!");
        }
        if (!ObjectUtils.nullSafeEquals(user.getPassword(), request.getPassword())) {
            return R.failed("密码不正确!");
        }
        return R.success(user);
    }
}
